﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace Coater.UC
{
    public partial class ucNumberKeypad : UserControl
    {
        public ucNumberKeypad()
        {
            InitializeComponent();

            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true); //双缓冲
            SetStyle(ControlStyles.DoubleBuffer, true); //双缓冲
            SetStyle(ControlStyles.SupportsTransparentBackColor, false);
        }

        private void btn_MouthDown(object obj, MouseEventArgs e)
        {
            Control btn = (Control)obj;
            btn.BackColor = Color.FromArgb(200, 200, 200);
            btn.ForeColor = Color.Black;
        }

        private void btn_MouthUp(object obj, MouseEventArgs e)
        {
            Control btn = (Control)obj;
            btn.BackColor = Color.Black;
            btn.ForeColor = Color.White;
        }

        private void btn_Click(object sender, EventArgs e)
        {
            SendKeys.SendWait("{" + ((Control)sender).Tag.ToString() + "}");
        }

        private void ucNumberKeypad_Resize(object sender, EventArgs e)
        {
            int width = (this.Width - 3) / 4 - 3;
            int hetght = width * 3 / 4;
            if ((hetght + 3) * 5 + 3 > Height)
            {
                Height = (hetght + 3) * 5 + 3;
            }
            btnBackSpace.Location = new Point(3, 3);
            btnBackSpace.Size = new Size(width, hetght);

            btnDivide.Location = new Point(3 + width + 3, 3);
            btnDivide.Size = new Size(width, hetght);

            btnMultiply.Location = new Point(3 + (width + 3) * 2, 3);
            btnMultiply.Size = new Size(width, hetght);

            btnSubtract.Location = new Point(3 + (width + 3) * 3, 3);
            btnSubtract.Size = new Size(width, hetght);

            btn7.Location = new Point(3, 3 + hetght + 3);
            btn7.Size = new Size(width, hetght);

            btn4.Location = new Point(3, 3 + (hetght + 3) * 2);
            btn4.Size = new Size(width, hetght);

            btn1.Location = new Point(3, 3 + (hetght + 3) * 3);
            btn1.Size = new Size(width, hetght);

            btn0.Location = new Point(3, 3 + (hetght + 3) * 4);
            btn0.Size = new Size(width * 2 + 3, hetght);

            btn8.Location = new Point(btnDivide.Location.X, btn7.Location.Y);
            btn8.Size = new Size(width, hetght);

            btn9.Location = new Point(btnMultiply.Location.X, btn7.Location.Y);
            btn9.Size = new Size(width, hetght);

            btnAdd.Location = new Point(btnSubtract.Location.X, btn7.Location.Y);
            btnAdd.Size = new Size(width, hetght * 2 + 3);

            btn5.Location = new Point(btnDivide.Location.X, btn4.Location.Y);
            btn5.Size = new Size(width, hetght);

            btn6.Location = new Point(btnMultiply.Location.X, btn4.Location.Y);
            btn6.Size = new Size(width, hetght);

            btn2.Location = new Point(btnDivide.Location.X, btn1.Location.Y);
            btn2.Size = new Size(width, hetght);

            btn3.Location = new Point(btnMultiply.Location.X, btn1.Location.Y);
            btn3.Size = new Size(width, hetght);

            btnEnter.Location = new Point(btnSubtract.Location.X, btn1.Location.Y);
            btnEnter.Size = new Size(width, hetght * 2 + 3);

            btnDot.Location = new Point(btnMultiply.Location.X, btn0.Location.Y);
            btnDot.Size = new Size(width, hetght);
        }
    }

}
